<?php
namespace app\index\controller;
use service\services\QuestionService;
use service\services\UserService;
use model\index\UserAbility;
use think\Request;
use model\index\UserAbilityStatus;
class Index extends Base
{
    public function index(){
        return $this->fetch();
    }

    public function user_ability(){
        return $this->fetch("");
    }
    public function user_ability1(){
        $username=input('field_key','');
        if(input('field_key','')=='username'){
            unset($_REQUEST['field_key']);
            $data=\think\Db::name('user')->where(['username'=> input('field_val','')])->find();
            if($data){
                $_REQUEST['field_key']='user_id';
                $_REQUEST['field_val']=$data['id'];
                echo $_SERVER['PATH_INFO'].'?'. http_build_query($_REQUEST);
                return $this->redirect($_SERVER['PATH_INFO'].'?'. http_build_query($_REQUEST));
            }else{
                $_REQUEST['field_key']='user_id';
                $_REQUEST['field_val']=0;
                echo $_SERVER['PATH_INFO'].'?'. http_build_query($_REQUEST);
                return $this->redirect($_SERVER['PATH_INFO'].'?'. http_build_query($_REQUEST));
            }
        }
        return $this->finder(
                'index',
                'user_ability', //查询表
                [],//条件
                [
                    'title'=>'列表', 
                    'is_detail'=>false,
                    'detail_url'=> '',
                     'finder_path'=> '',
                    'actions'=>[
                       
                ]
            ],  new UserAbility()
                ,'id',[],'id desc'
        );
    }
    public function user_ability_status1(){
         $username=input('field_key','');
        if(input('field_key','')=='username'){
            unset($_REQUEST['field_key']);
            $data=\think\Db::name('user')->where(['username'=> input('field_val','')])->find();
            if($data){
                $_REQUEST['field_key']='user_id';
                $_REQUEST['field_val']=$data['id'];
                echo $_SERVER['PATH_INFO'].'?'. http_build_query($_REQUEST);
                return $this->redirect($_SERVER['PATH_INFO'].'?'. http_build_query($_REQUEST));
            }else{
                $_REQUEST['field_key']='user_id';
                $_REQUEST['field_val']=0;
                echo $_SERVER['PATH_INFO'].'?'. http_build_query($_REQUEST);
                return $this->redirect($_SERVER['PATH_INFO'].'?'. http_build_query($_REQUEST));
            }
        }
        return $this->finder(
                'index',
                'user_ability_status', //查询表
                [],//条件
                [
                    'title'=>'列表', 
                    'is_detail'=>true,
                    'detail_url'=> url('index/Index/finderDetail', '', true, true),
                     'finder_path'=> 'Index/user_ability_status',
                    'actions'=>[
                       
                ]
            ],  new UserAbilityStatus()
                ,'id',[],'id desc'
        );
    }
    public function user_ability_status(){
        return $this->fetch("");
    }
    public function user(){
        return $this->fetch();
    }
    public function userS(){
        $post=input();
        $where='';
        if($post){
            foreach($post as $k=>$v){
                $where.=$k.'="'.$v.'"&&';
            }
        }
        $where=rtrim($where, '&&');
        $data=\think\Db::name('user')->where($where)->select();
        echo "<pre>";
        print_r($data);
        echo "</pre>";
        echo "<a href='javascript:history.go(-1);'  >返回上一页</a>";
    }
}